import {createRouter, createWebHashHistory} from "vue-router"

import Login from './pages/Login.vue'
import Homepage from './pages/Homepage.vue'

const routes = [
	{
		path: '/login',
		name: 'Login',
		component: Login
	},
	{
		path: '/',
		name: 'Homepage',
		component: Homepage
	}
]

const router = createRouter({
    history: createWebHashHistory(),
    routes
});

router.beforeEach((to, from, next) => {
    const token = localStorage.getItem('token');
    if (!token && to.path !== '/login') {
        next('/login');
    } else {
        next();
    }
});

export default router;